import Network from '../utils/network';

export interface HomeGoalMessage {
  background_pic: string;
  can_jump: boolean; // 是否可跳转
  code_card_info: NVPair; // 码牌信息
  terminal_info: NVPair; // 设备信息
  logo: string[];
}

/**【v5.1.0】首页目标进度 POST /app/home/goal?v=4  */
export const getProgressMessage = () => {
  return Network.post<HomeGoalMessage>({
    url: '/app/home/goal?v=4',
  }).then(res => res.data);
};

export interface Activity {
  title: string;
  summary: string;
  btn_text: string;
  btn_color: string;
  icon: string;
  action: string;
  identity_verified: boolean;
  corner_icon: string;
}
export interface ActivityInfo {
  title: string;
  functions: Activity[];
}

export function fetchHotActivity(type: string): Promise<ActivityInfo> {
  return Network.post({
    url: '/app/home/activity',
    data: {
      type,
    },
  }).then(({data}) => data.data);
}

export interface SwiperElement {
  pic_url: string;
  url: string;
  title?: string;
  onPress?: () => void;
}

export const fetchSwiper = () =>
  Network.post<{
    data: SwiperElement[];
  }>({
    url: '/app/home/activity/banner',
  }).then(({data}) => data.data);
export interface PolicyHistoryTableData {
  title: string;
  body: Array<{
    old: string;
    new?: string;
    is_rise?: boolean; // 颜色标志：true绿，false红，null无
  }>[];
}

interface PolicyHistoryItem {
  time: string;
  name: string; // 机构产品名称
  info?: {
    // 政策调整有
    old_level_name: string;
    new_level_name: string;
    is_rise: boolean;
    remark: string;
  };
  policies: PolicyHistoryTableData[];
}

// 测试data list
export const fetchPolicyAdjustmentHistory = (offset: number, user?: any) => {
  return Network.post<{
    history: PolicyHistoryItem[];
  }>({
    url: '/app/mine/policy/record/adjust',
    data: {
      user,
      offset,
    },
  }).then(({data}) => data.history);
};
